package com.wanji.single_point.controller;

import com.wanji.single_point.pojo.AlarmResult;
import com.wanji.single_point.pojo.CountResult;
import com.wanji.single_point.pojo.PutParam;
import com.wanji.single_point.pojo.RadarResult;
import com.wanji.single_point.service.AlarmService;
import com.wanji.single_point.service.CountService;
import com.wanji.single_point.service.RadarService;
import com.wanji.single_point.utils.ResultUtil;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.Map;
import java.util.concurrent.ConcurrentHashMap;

/**
 * @author xinyingjie
 */
@CrossOrigin
@RestController
@RequestMapping("/synthesize")
public class ComController {

    /**
     * 存放用户信息，key:设备Id,value:用户传递过来的参数
     */
    public static Map<String, PutParam> user = new ConcurrentHashMap<>();


    @Autowired
    private CountService countService;
    @Autowired
    private AlarmService alarmService;
    @Autowired
    private RadarService radarService;


    /**\
     * @RequestParam(value = "deviceId", defaultValue = "") String deviceId,
     *                                @RequestParam(value = "realCode", defaultValue = "") String realCode,
     *                                @RequestParam(value = "testCode", defaultValue = "") String testCode,
     *                                @RequestParam(value = "beginTime", defaultValue = "") Long beginTime,
     *                                @RequestParam(value = "endTime", defaultValue = "") Long endTime
     */
    /**
     * 接收传递的参数
     *
     * @return
     */
    @PostMapping("/putParam")
    public ResultUtil putParam(@RequestBody PutParam param) {
        String deviceId = "962464";
        String realCode = "GW42940403";
        String testCode = "GW42940403";
        Long beginTime = 1560802113491L;
        Long endTime = 1760802113491L;
        PutParam param1 = countService.putParamer(realCode, testCode, beginTime, endTime);
        String userId = deviceId + realCode + testCode;

        user.put(userId, param);

        return ResultUtil.success(200, "返回结果成功", "ok");
    }
//    @RequestParam(value = "deviceId", defaultValue = "") String deviceId,
//    @RequestParam(value = "realCode", defaultValue = "") String realCode,
//    @RequestParam(value = "testCode", defaultValue = "") String testCode

    /**
     * 根据userId获取count返回结果
     *
     * @return
//     */
    @GetMapping("/count/getResult")
    public CountResult countGetResult() {
        String deviceId = "962464";
        String realCode = "GW42940400";
        String testCode = "GW42940400";
        String userId = deviceId + realCode + testCode;
        CountResult result = countService.getResult(userId);
        System.out.println(result);
        if (result == null) {
            return null;
        }
        return result;
    }
//
//    @RequestParam(value = "deviceId", defaultValue = "") String deviceId,
//    @RequestParam(value = "realCode", defaultValue = "") String realCode,
//    @RequestParam(value = "testCode", defaultValue = "") String testCode
    /**
     * 根据userId获取alarm返回结果
     *

     * @return
     * @throws Exception
     */
    @GetMapping("/alarm/getResult")

    public AlarmResult alarmGetResult() throws Exception {
        String deviceId = "962464";
        String realCode = "GW42940404";
        String testCode = "GW42940404";
        String userId = deviceId + realCode + testCode;
        AlarmResult result = alarmService.getResult(userId);
        if (result == null) {
            return null;
        }
        return result;
    }

//    @RequestParam(value = "deviceId", defaultValue = "") String deviceId,
//    @RequestParam(value = "realCode", defaultValue = "") String realCode,
//    @RequestParam(value = "testCode", defaultValue = "") String testCode
    /**
     * 根据userId获取radar返回结果
     *
     *

     */
    @GetMapping("/radar/getResult")

    public RadarResult radarGetResult() {
        String deviceId = "962464";
        String realCode = "GW42940408";
        String testCode = "GW42940408";
        String userId = deviceId + realCode + testCode;
        RadarResult result = radarService.getResult(userId);
        System.out.println(result);
        if (result == null) {
            return null;
        }
        return result;
    }


}
